# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgname=busybox
pkgver=1.22.1
pkgrel=2
pkgdesc="BusyBox: The Swiss Army Knife of Embedded Linux"
arch=('i686' 'x86_64')
url="http://www.busybox.net/"
license=('GPL2')
depends=('msys2-runtime')
install=busybox.install
source=("http://busybox.net/downloads/${pkgname}-${pkgver}.tar.bz2"
        "busybox-cygwin.patch"
        "fixsyscalls.patch"
        "msys2.config"
        "pwdW.patch")

sha1sums=('d6e96fefb6f0fb8079f27468b9bf22d8dd96108e'
          'a0d4886454f30dbbcfd464472017ab2fa11297e9'
          '060e6b5d06ac5f9034a4857c37259d346df9eb5a'
          'd676f52cd27c99f173b8cb003b1161063417d534'
          'b49fe269a01c3b73016c33a00e417d84f0c512b0')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/busybox-cygwin.patch
  patch -p1 -i ${srcdir}/fixsyscalls.patch
  #patch -p1 -i ${srcdir}/pwdW.patch
  cp ${srcdir}/msys2.config ${srcdir}/${pkgname}-${pkgver}/.config
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  #make oldconfig
  #CFLAGS='-O2 -static-libgcc'
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  #install busybox
  mkdir -p ${pkgdir}/usr/bin
  cp ${srcdir}/${pkgname}-${pkgver}/busybox.exe ${pkgdir}/usr/bin

  # license
  install -m644 -D LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}
